package com.hjs.util;

import java.math.BigDecimal;

/**
 * @auther 韩劲松
 * @school 西安邮电大学
 * @create 2018-12-28 17:18
 */
public class BigDecimalUtil {

    public static BigDecimal add(Double a,Double b){
        BigDecimal a1 = new BigDecimal(Double.toString(a));
        BigDecimal b1 = new BigDecimal(Double.toString(b));
        return a1.add(b1);
    }

    public static BigDecimal snb(Double a,Double b){
        BigDecimal a1 = new BigDecimal(Double.toString(a));
        BigDecimal b1 = new BigDecimal(Double.toString(b));
        return a1.subtract(b1);
    }

    public static BigDecimal mul(Double a,Double b){
        BigDecimal a1 = new BigDecimal(Double.toString(a));
        BigDecimal b1 = new BigDecimal(Double.toString(b));
        return a1.multiply(b1);
    }

    public static BigDecimal div(Double a,Double b){
        BigDecimal a1 = new BigDecimal(Double.toString(a));
        BigDecimal b1 = new BigDecimal(Double.toString(b));
        return a1.divide(b1,2,BigDecimal.ROUND_HALF_UP);//四舍五入，保留两位小数
    }

}
